package cn.drj.myutils.adapter;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;

import cn.drj.myutils.adapter.ViewHolder.DRJRecyclerViewHolder;

/**
 * Created by mk on 2017/11/8.
 */

public class Listener {

    public interface DRJOnItemChildClickListener {
        void onItemChildClick(ViewGroup parent, View childView, int position);
    }

    public interface DRJOnItemChildLongClickListener {
        boolean onItemChildLongClick(ViewGroup parent, View childView, int position);
    }

    public interface DRJOnItemChildCheckedChangeListener {
        void onItemChildCheckedChanged(ViewGroup parent, CompoundButton childView, int position, boolean isChecked);
    }

    public interface DRJOnRVItemClickListener {
        void onRVItemClick(ViewGroup parent, View itemView, int position);
    }

    public interface DRJOnRVItemLongClickListener {
        boolean onRVItemLongClick(ViewGroup parent, View itemView, int position);
    }

    public interface DRJOnRVItemChildTouchListener {
        boolean onRvItemChildTouch(DRJRecyclerViewHolder holder, View childView, MotionEvent event);
    }

    public abstract static class DRJOnNoDoubleClickListener implements View.OnClickListener {
        private int mThrottleFirstTime = 1000;
        private long mLastClickTime = 0;

        public DRJOnNoDoubleClickListener() {
        }

        public DRJOnNoDoubleClickListener(int throttleFirstTime) {
            mThrottleFirstTime = throttleFirstTime;
        }

        @Override
        public void onClick(View v) {
            long currentTime = System.currentTimeMillis();
            if (currentTime - mLastClickTime > mThrottleFirstTime) {
                mLastClickTime = currentTime;
                onNoDoubleClick(v);
            }
        }

        public abstract void onNoDoubleClick(View v);
    }

    public Listener(){

    }

}
